﻿using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace estoque
{
    class PriorityBrushConverter : IValueConverter
    {
        private static LinearGradientBrush specialBrush;

        private static Brush SpecialBrush
        {
            get
            {
                if (specialBrush == null)
                {
                    specialBrush = new LinearGradientBrush();
                    specialBrush.EndPoint = new Point(0.5, 1);
                    specialBrush.MappingMode = BrushMappingMode.RelativeToBoundingBox;
                    specialBrush.StartPoint = new Point(0.5, 0);
                    specialBrush.RelativeTransform = new TransformGroup();
                    ((TransformGroup)specialBrush.RelativeTransform).Children.Add(new RotateTransform { Angle = 103 });
                    specialBrush.GradientStops.Add(new GradientStop { Color = Colors.Black, Offset = 0 });
                    specialBrush.GradientStops.Add(new GradientStop { Color = Colors.Black, Offset = 1 });
                    specialBrush.GradientStops.Add(new GradientStop { Color = Colors.White, Offset = 0.25 });
                    specialBrush.GradientStops.Add(new GradientStop { Color = Colors.LawnGreen, Offset = 0.5 });
                    specialBrush.GradientStops.Add(new GradientStop { Color = Colors.White, Offset = 0.75 });
                }

                return specialBrush;
            }
        }

        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Priority result;
            if (Enum.TryParse<Priority>(value.ToString(), out result))
            {
                switch (result)
                {
                    case Priority.special:
                        return Brushes.SlateBlue;
                    case Priority.A:
                        return Brushes.Red;
                    case Priority.B:
                        return Brushes.Yellow;
                    case Priority.C:
                        return Brushes.Green;
                    default:
                        return Brushes.Gray;
                }
            }

            return Brushes.Green;
        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new System.NotImplementedException();
        }
    }
}